package com.pocketsweet.ui.uilib.wheelview;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.pocketsweet.R;
import com.pocketsweet.ui.uilib.wheelcity.OnWheelChangedListener;
import com.pocketsweet.ui.uilib.wheelcity.WheelTimeView;
import com.pocketsweet.ui.uilib.wheelcity.WheelView;
import com.pocketsweet.ui.uilib.wheelcity.adapters.AbstractWheelTextAdapter;

public class wheelTime {
	private String cityTxt;
	private Context context;
	private View myView;
	private String porvinceStr;
	private String cityStr;
//	private String countryStr;

	public wheelTime(Context context) {
		initView(context);
	}

	private void initView(Context context) {
		this.context = context;
		View contentView = LayoutInflater.from(context).inflate(
				R.layout.wheeltime_layout, null);
		final WheelTimeView country = (WheelTimeView) contentView
				.findViewById(R.id.wheelcity_country);
		country.setVisibleItems(3);
		country.setViewAdapter(new CountryAdapter(context));

		final String cities[][] = TimeContinuedData.CITIES;
		final String ccities[][][] = TimeContinuedData.COUNTIES;

		country.addChangingListener(new OnWheelChangedListener() {
			public void onChanged(WheelView wheel, int oldValue, int newValue) {
				cityTxt = TimeContinuedData.PROVINCES[country.getCurrentItem()]
						;
				porvinceStr = TimeContinuedData.PROVINCES[country.getCurrentItem()];
			}

			@Override
			public void onChanged(WheelTimeView wheelTimeView, int oldValue,
					int newValue) {
				// TODO Auto-generated method stub
				cityTxt = TimeContinuedData.PROVINCES[country.getCurrentItem()]
						;
				porvinceStr = TimeContinuedData.PROVINCES[country.getCurrentItem()];
			}
		});


		country.setCurrentItem(1);
		this.myView = contentView;
	}

	public View getView() {
		return this.myView;
	}

	public String getText() {
		return this.cityTxt;
	}

	public String getProvinceText() {
		return this.porvinceStr;
	}

	public String getCityText() {
		return this.cityStr;
	}

	/**
	 * Adapter for countries
	 */
	private class CountryAdapter extends AbstractWheelTextAdapter {
		// Countries names
		private String countries[] = TimeContinuedData.PROVINCES;

		/**
		 * Constructor
		 */
		protected CountryAdapter(Context context) {
			super(context, R.layout.wheelcity_country_layout, NO_RESOURCE);
			setItemTextResource(R.id.wheelcity_country_name);
		}

		@Override
		public View getItem(int index, View cachedView, ViewGroup parent) {
			View view = super.getItem(index, cachedView, parent);
			return view;
		}

		@Override
		public int getItemsCount() {
			return countries.length;
		}

		@Override
		protected CharSequence getItemText(int index) {
			return countries[index];
		}
	}
}